﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.Text;
using Zj.DDDSample.Domain.Core;

namespace Zj.DDDSample.Repositories.EntityFrameworkCore.Models.Mappings
{  
    /// <summary>
    /// Item fluent api mapping.
    /// </summary>
    public class ItemMap
      : IEntityTypeConfiguration<Item>
    {
        public void Configure(EntityTypeBuilder<Item> builder)
        {
            //table
            builder.ToTable("Item", "dbo");

            //keys
            builder.HasKey(t => t.Id);

            //properties
            builder.Property(t => t.Id)
                .HasColumnName("Id")
                .IsRequired();

            builder.Property(t => t.ProjectId)
               .HasColumnName("ProjectId")
               .IsRequired();

            builder.Property(t => t.Description)
                .HasColumnName("Description")
                .IsRequired();

            builder.Property(t => t.Title)
                .HasColumnName("Title")
                .HasMaxLength(50)
                .IsRequired();

            builder.Property(t => t.Time)
                .HasColumnName("Time")
                .IsRequired();
        }
    }
}
